package dic_value_type

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type DicValueType int

const (
	String DicValueType = iota + 1
	Integer
	Decimal
	Bool
	JsonObject
	JsonArray
)

func (e DicValueType) Code() int32 {
	return int32(e)
}

func (e DicValueType) Des() string {
	return enums.BE(e).Des
}

func (e DicValueType) Enum() string {
	return enums.BE(e).Enum
}

func (e DicValueType) Val() int {
	return int(e)
}

func (e *DicValueType) UnmarshalJSON(value []byte) error {
	*e = DicValueType(enums.UnmarshalEnum(value))
	return nil
}

func (e DicValueType) MarshalJSON() ([]byte, error) {
	switch e {
	case String:
		return enums.JsonObj(int(e), "String", "字符")
	case Integer:
		return enums.JsonObj(int(e), "Integer", "整数")
	case Decimal:
		return enums.JsonObj(int(e), "Decimal", "浮点")
	case Bool:
		return enums.JsonObj(int(e), "Bool", "布尔")
	case JsonObject:
		return enums.JsonObj(int(e), "JsonObject", "JsonObject")
	case JsonArray:
		return enums.JsonObj(int(e), "JsonArray", "JsonArray")
	}
	return []byte(strconv.Itoa(int(e))), nil
}

func SelectOptions() []enums.SelectOptions {
	return enums.ToSelectOptions([]any{String, Integer, Decimal, Bool, JsonObject, JsonArray})
}
